import java.util.concurrent.Semaphore;

public class MyBlockingQueue<T> {

    /**
     * 生产者使用的信号量
     */
    private final Semaphore emptyCount;
    /*
    * 消费者使用的信号量
    * */
    private final Semaphore fillCount;
    private T data;

    public MyBlockingQueue() {
        emptyCount = new Semaphore(1);
        fillCount = new Semaphore(0);
    }

    public void put(T data) throws InterruptedException {

        emptyCount.acquire();

        synchronized (this){
            this.data = data;
        }

        fillCount.release();
    }


    public T get() throws InterruptedException {
        fillCount.acquire();
        T temp;
        synchronized (this){
            temp = this.data;
        }

        emptyCount.release();

        return temp;
    }
}
